package common.filter;

import common.constant.TokenConstant;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author: 郑国荣
 * @Date: 2024-03-29-17:08
 * @Description:
 */
public class ServiceFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("进入过滤器========");
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        String gateway = request.getHeader(TokenConstant.FILTER_KEY_NAME);
        System.out.println("gateway: " + gateway);
        // 获取路径
        String path = request.getRequestURI();
        System.out.println("请求路径：" + path);
        // 获取请求ip
        String ip = request.getRemoteAddr();
        System.out.println("请求ip：" + ip);
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
